#!/usr/etc/env python
#-*- coding:utf-8 -*-
'''
    TODO
'''
from flask import Blueprint , render_template , g , flash , session , request 
from flask import redirect , url_for 
from apps import app

user = Blueprint('user',__name__)

@app.route('/user/login', methods=['GET','POST'])
def login():
    error = True
    if request.method == 'POST':
        #cur = g.db.execute('select title , text  from demo_user order by id desc')
        #user = [dict(title=row[0],text=row[1]) for row in cur.fetchone()]
        #print repr(user)
        if request.form['username'] != app.config['USERNAME']:
            error = 'Invalid username'
        elif request.form['password'] != app.config['PASSWORD']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            flash('You Were logged in')
            return redirect(url_for('show_entries'))
    return render_template('login.html', error=error)
@app.route('/user/logout')
def logout():
    session.pop('logged_in', None)
    flash('You were logged out')
    return redirect(url_for('show_entries'))


